home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gdb
/
gdb_18s.zoo
/
valops.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-25
|
21KB
|
780 lines
/* Perform non-arithmetic operations on values, for GDB.
Copyright (C) 1986, 1987 Free Software Foundation, Inc.
GDB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone
for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.
Refer to the GDB General Public License for full details.
Everyone is granted permission to copy, modify and redistribute GDB,
but only under the conditions described in the GDB General Public
License. A copy of this license is supposed to have been given to you
along with GDB so you can know your rights and responsibilities. It
should be in a file named COPYING. Among other things, the copyright
notice and this notice must be preserved on all copies.
In other words, go ahead and share GDB, but don't try to stop
anyone else from sharing it farther. Help stamp out software hoarding!
*/
#include "defs.h"
#include "param.h"
#include "symtab.h"
#include "value.h"
#include "frame.h"
#include "inferior.h"
#ifdef atarist
extern int gcc_mshort;
#endif
/* Cast value ARG2 to type TYPE and return as a value.
More general than a C cast: accepts any two types of the same length,
and if ARG2 is an lvalue it can be cast into anything at all. */
value
value_cast (type, arg2)
struct type *type;
register value arg2;
{
register enum type_code code1;
register enum type_code code2;
register int scalar;
/* Coerce arrays but not enums. Enums will work as-is
and coercing them would cause an infinite recursion. */
if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_ENUM)
COERCE_ARRAY (arg2);
code1 = TYPE_CODE (type);
code2 = TYPE_CODE (VALUE_TYPE (arg2));
scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT
|| code2 == TYPE_CODE_ENUM);
if (code1 == TYPE_CODE_FLT && scalar)
return value_from_double (type, value_as_double (arg2));
else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM)
&& (scalar || code2 == TYPE_CODE_PTR))
return value_from_long (type, value_as_long (arg2));
else if (TYPE_LENGTH (type) == TYPE_LENGTH (VALUE_TYPE (arg2)))
{
VALUE_TYPE (arg2) = type;
return arg2;
}
else if (VALUE_LVAL (arg2) == lval_memory)
return value_at (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
else if (code1 == TYPE_CODE_VOID)
{
return value_zero (builtin_type_void, not_lval);
}
else
error ("Invalid cast.");
}
/* Create a value of type TYPE that is zero, and return it. */
value
value_zero (type, lv)
struct type *type;
enum lval_type lv;
{
register value val = allocate_value (type);
bzero (VALUE_CONTENTS (val), TYPE_LENGTH (type));
VALUE_LVAL (val) = lv;
return val;
}
/* Return the value with a specified type located at specified address. */
value
value_at (type, addr)
struct type *type;
CORE_ADDR addr;
{
register value val = allocate_value (type);
read_memory (addr, VALUE_CONTENTS (val), TYPE_LENGTH (type));
VALUE_LVAL (val) = lval_memory;
VALUE_ADDRESS (val) = addr;
return val;
}
/* Store the contents of FROMVAL into the location of TOVAL.
Return a new value with the location of TOVAL and contents of FROMVAL. */
value
value_assign (toval, fromval)
register value toval, fromval;
{
register struct type *type = VALUE_TYPE (toval);
register value val;
char raw_buffer[MAX_REGISTER_RAW_SIZE];
char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
int use_buffer = 0;
COERCE_ARRAY (fromval);
if (VALUE_LVAL (toval) != lval_internalvar)
fromval = value_cast (type, fromval);
/* If TOVAL is a special machine register requiring conversion
of program values to a special raw format,
convert FROMVAL's contents now, with result in `raw_buffer',
and set USE_BUFFER to the number of bytes to write. */
if (VALUE_REGNO (toval) >= 0
&& REGISTER_CONVERTIBLE (VALUE_REGNO (toval)))
{
int regno = VALUE_REGNO (toval);
if (VALUE_TYPE (fromval) != REGISTER_VIRTUAL_TYPE (regno))
fromval = value_cast (REGISTER_VIRTUAL_TYPE (regno), fromval);
bcopy (VALUE_CONTENTS (fromval), virtual_buffer,
REGISTER_VIRTUAL_SIZE (regno));
REGISTER_CONVERT_TO_RAW (regno, virtual_buffer, raw_buffer);
use_buffer = REGISTER_RAW_SIZE (regno);
}
switch (VALUE_LVAL (toval))
{
case lval_internalvar:
set_internalvar (VALUE_INTERNALVAR (toval), fromval);
break;
case lval_internalvar_component:
set_internalvar_component (VALUE_INTERNALVAR (toval),
VALUE_OFFSET (toval),
VALUE_BITPOS (toval),
VALUE_BITSIZE (toval),
fromval);
break;
case lval_memory:
if (VALUE_BITSIZE (toval))
{
int val;
read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
&val, sizeof val);
modify_field (&val, value_as_long (fromval),
VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
&val, sizeof val);
}
else if (use_buffer)
write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
raw_buffer, use_buffer);
else
write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
break;
case lval_register:
if (VALUE_BITSIZE (toval))
{
int val;
read_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
&val, sizeof val);
modify_field (&val, value_as_long (fromval),
VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
&val, sizeof val);
}
else if (use_buffer)
write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
raw_buffer, use_buffer);
else
write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
break;
default:
error ("Left side of = operation is not an lvalue.");
}
#if 1
/* Return a value just like TOVAL except with the contents of FROMVAL
(except in the case of the type if TOVAL is an internalvar). */
if (VALUE_LVAL (toval) == lval_internalvar
|| VALUE_LVAL (toval) == lval_internalvar_component)
{
type = VALUE_TYPE (fromval);
}
val = allocate_value (type);
bcopy (toval, val, VALUE_CONTENTS_RAW (val) - (char *) val);
bcopy (VALUE_CONTENTS (fromval), VALUE_CONTENTS_RAW (val), TYPE_LENGTH (type));
VALUE_TYPE (val) = type;
return val;
#else
/* Return a value just like TOVAL except with the contents of FROMVAL. */
val = allocate_value (type);
bcopy (toval, val, VALUE_CONTENTS (val) - (char *) val);
bcopy (VALUE_CONTENTS (fromval), VALUE_CONTENTS (val), TYPE_LENGTH (type));
return val;
#endif
}
/* Extend a value VAL to COUNT repetitions of its type. */
value
value_repeat (arg1, count)
value arg1;
int count;
{
register value val;
if (VALUE_LVAL (arg1) != lval_memory)
error ("Only values in memory can be extended with '@'.");
if (count < 1)
error ("Invalid number %d of repetitions.", count);
val = allocate_repeat_value (VALUE_TYPE (arg1), count);
read_memory (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1),
VALUE_CONTENTS (val),
TYPE_LENGTH (VALUE_TYPE (val)) * count);
VALUE_LVAL (val) = lval_memory;
VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1);
return val;
}
value
value_of_variable (var)
struct symbol *var;
{
value val;
val = read_var_value (var, (CORE_ADDR) 0);
if (val == 0)
error ("Address of symbol \"%s\" is unknown.", SYMBOL_NAME (var));
return val;
}
/* Given a value which is an array, return a value which is
a pointer to its first element. */
value
value_coerce_array (arg1)
value arg1;
{
register struct type *type;
register value val;
if (VALUE_LVAL (arg1) != lval_memory)
error ("Attempt to take address of value not located in memory.");
/* Get type of elements. */
if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY)
type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1